//
//  SEPrescriptionModel.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/4/21.
//

import HandyJSON
/// 处方状态：0未审核，1审核通过2驳回,3付款成功,4医生撤销,5未开药
enum SEPrescriptionStatus: Int, HandyJSONEnum, Codable {
    case unreviewed, passed, rejected, paid, revoked, noDrug
    
    var text: String? {
        switch self {
        case .unreviewed:   return "审核中"
        case .passed:       return "审核通过"
        case .rejected:     return "被驳回"
        case .paid:         return "患者已支付"
        case .revoked:      return "已撤销"
        case .noDrug:       return "未开药"
        }
    }
    
    var desc: String? {
        switch self {
        case .unreviewed,
             .rejected: return "（可撤销）"
        case .passed,
             .paid:     return "（不可撤销）"
        case .revoked,
             .noDrug:   return nil
        }
    }
    
    var textColor: UIColor {
        switch self {
        case .unreviewed,
             .passed,
             .paid:         return Asset.main.color
        case .rejected:     return Asset.warn.color
        case .revoked,
             .noDrug:       return Asset.textGray.color
        }
    }
    
    var descColor: UIColor { return UIColor(hex: "#CCCCCC") }
    
    var deleteHidden: Bool {
        switch self {
        case .unreviewed,
             .rejected: return false
        default:        return true
        }
    }
    
    var statusLabelHidden: Bool {
        switch self {
        case .passed: return true
        default:      return false
        }
    }
    
    var confirmButtonHidden: Bool {
        switch self {
        case .rejected: return false
        default:        return true
        }
    }
    
    var canEdit: Bool {
        switch self {
        case .rejected: return true
        default:        return false
        }
    }
}

enum SEPrescriptionMode {
    case prescription(_ inquiryId: String, _ id: String, _ isNew: Bool)
    case template(_ id: String, _ isNew: Bool)
    
    var message: String {
        switch self {
        case .prescription: return "处方已提交"
        case .template:     return "处方模板已保存"
        }
    }
    
    var title: String {
        switch self {
        case let .prescription(_, _, isNew): return isNew ? "新建处方" : "处方详情"
        case let .template(_, isNew):        return isNew ? "新建处方模板" : "处方模板详情"
        }
    }
}

struct SEPrescriptionModel: HandyJSON {
    var id: String?
    var createTime: String?
    var updateTime: String?
    var creator: String?
    var `operator`: String?
    var isDeleted: Int = 0
    var bisType: Int = 0        // 业务类型
    var bisId: String?          // 业务id
    var patientId: String?
    var patientName: String?
    var patientSex: Int = 0
    var patientAge: String?
    var patientPhone: String?
    var patientIdcard: String?
    var doctorId: String?       // 开处方的医生id
    var doctor: String?         // 开处方的医生
    var jobTitle: String?
    var hospitalId: String?     // 开方医院id
    var hospitalName: String?
    var totalExpense: Int = 0   // 处方的总费用
    var auditorId: String?      // 审核人id
    var auditor: String?        // 审核人
    var status: SEPrescriptionStatus = .unreviewed  // 处方状态：0未审核，1审核通过2驳回,3付款成功,4医生撤销
    var passTime: String?       // 审核时间
    var reject: String?         // 驳回理由
    var isChild: Int = 0        // 是否儿童处方（1是，0否）
    var proposal: String?       // 医生建议
    var remark: String?         // 用药嘱托
    var list: [SEPrescriptionDrug]?
    var detailDtos: [SEPrescriptionDiagnosis]?
    var illness: String?        // 病情描述
    var conTime: String?        // 问诊时间
    var result: String?         // 诊断结果
    var orderStatus: Int = 0    // 订单状态（1待付款，2待取药，3待发货，4待签收，5待评价，6已完成，7已取消，8退款关闭）
    var drugNames: String?      // 药品名称
    var diagnoseName: String?
    
    var name: String?           // 处方模板名称
    var diagName: String?
    var detailTemp: [SEPrescriptionDrug]?
    var diagnoseTemp: [SEPrescriptionDiagnosis]?
}

struct SEPrescriptionList: HandyJSON {
    var pageNum: Int = 0
    var pageSize: Int = 0
    var total: Int = 0
    var totalPage: Int = 0
    var list: [SEPrescriptionModel]?
}
